home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 076-100 / scopedisk94 / finish / finish.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-19  |  2.7 KB  |  102 lines

  1. /* finish v1.2 - program to wait till all activity on a selected
  2.             disk drive is finished
  3.                    by Mark Wolfskehl 
  4.             type finish.doc for instructions */
  5. #include <exec/types.h>
  6. #include <exec/nodes.h>
  7. #include <exec/lists.h>
  8. #include <exec/ports.h>
  9. #include <devices/trackdisk.h>
  10.  
  11. int val ( string )
  12.      char string[];
  13.  {
  14.    int value , place , endflag;
  15.    char chr;
  16.    value = 0;
  17.    place = 0;
  18.    endflag = 1;
  19.    chr = string[0]; 
  20.    while ( ( chr != '\0' )   &&   endflag )   
  21.     {
  22.       chr = string[place];  
  23.       if ( ( chr < '0' )   ||   ( chr > '9' ) )
  24.           endflag = 0;
  25.       else value = value * 10 + (chr - '0');
  26.       ++place;
  27.     }
  28.    return ( value );
  29.  }
  30.               
  31. int finish ( drive )
  32.      int drive;  
  33.  {
  34.    SHORT error;
  35.    struct MsgPort *diskport;
  36.    struct IOExtTD *diskreq;
  37.    struct MsgPort *CreatePort();
  38.    struct IORequest *CreateExtIO();
  39.    int counter;
  40.    if ( drive < 0 || drive > 2 )  return ( 100 ); 
  41.    diskport = CreatePort ( 0,0 );
  42.    if ( diskport == 0 ) return ( 100 ); /* error - terminate */
  43.    diskreq = (struct IOExtTD *) CreateExtIO ( diskport ,
  44.                            sizeof ( struct IOExtTD ) );
  45.    if ( diskreq == 0 )
  46.     {
  47.        DeletePort ( diskport );
  48.        return ( 100 );   /* error - terminate */
  49.     }
  50.     
  51.    error = OpenDevice ( TD_NAME , drive , diskreq , 0 ); /* Open drive */
  52.    if ( error )   /* error - terminate */
  53.     {  
  54.        DeleteExtIO ( diskreq , sizeof ( struct IOExtTD ) );
  55.        DeletePort ( diskreq );
  56.        return ( 100 );
  57.     }
  58.    counter = 0;
  59.    diskreq->iotd_Req.io_Command = TD_CHANGESTATE;
  60.    DoIO ( diskreq );
  61.    if ( !diskreq->iotd_Req.io_Actual ) /* Perform only if disk in drive */
  62.     {
  63.       do
  64.        {
  65.          diskreq->iotd_Req.io_Length = 0;       /* turn off disk motor */
  66.          diskreq->iotd_Req.io_Command = ETD_MOTOR;
  67.          DoIO ( diskreq ) ;
  68.          ++counter;
  69.        }
  70.       while ( ( counter <= 375 ) );  /* wait 375 times to make 
  71.                                       sure disk has stopped */  
  72.     }
  73.    CloseDevice ( diskreq );
  74.    DeleteExtIO ( diskreq , sizeof ( struct IOExtTD ) );
  75.    DeletePort ( diskport );
  76.    return ( (int)error );
  77.  }
  78.  
  79. void main ( argc , argv )
  80.   int argc;
  81.   char *argv[];
  82.    {      
  83.      int error;  
  84.      if ( argc < 2 )
  85.       {
  86.         error = finish ( 0 ); /* Default to DF0: */
  87.         if ( error ) printf ( "Error\n" ); 
  88.         exit ( error );
  89.       }
  90.      if ( !strcmp ( argv[1] , "?" ) )  /* Print the usage? */
  91.       {
  92.         printf ( "Finish v1.2 by Mark Wolfskehl\n" );
  93.         printf ( "Usage: finish <drive #>\n<drive #> is 0, 1 or 2.\n" );
  94.         exit ( 0 );
  95.       }
  96.      error = finish ( val ( argv[1] ) );
  97.      if ( error ) printf ( "Error\n");
  98.      exit ( error ); 
  99.  }
  100.  
  101.  
  102.